package com.entrogy.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.entrogy.bean.CourseHomeworkEntity;
import com.entrogy.bean.HomeworkEntity;
import com.entrogy.dao.HomeworkMapper;
import com.entrogy.service.HomeworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName HomeworkServiceImpl
 * @Description
 * @Author luoxingjiang
 * @Date 2019/7/22 0022 上午 11:15
 * @Version 1.0
 **/
@Service
public class HomeworkServiceImpl implements HomeworkService {

    @Autowired
    private HomeworkMapper homeworkMapper;

    @Override
    public List<HomeworkEntity> listHomeworkInfo(String teacherId, Integer schoolCode, Integer classId, Integer courseId) {
        return homeworkMapper.listHomeworkInfo(teacherId, schoolCode, classId, courseId);
    }

    @Override
    public Integer addHomework(HomeworkEntity homework) {
        //首先向作业表内插入数据
        int row = homeworkMapper.addHomework(homework);
        //然后向作业图片对应表内插入数据
        List<String> imageUrls = homework.getImageUrls();
        Integer homeworkId = homework.getId();
        if (imageUrls.size() > 0){
            int insertImageUrlrow = homeworkMapper.addHomeworkImageUrl(homeworkId,imageUrls);
        }
        return homeworkId;
    }

    @Override
    public List<String> listClassParentOpenId(Integer classId, Integer schoolCode) {
        return homeworkMapper.listClassParentOpenId(classId, schoolCode);
    }

    @Override
    public HomeworkEntity getHomeworkDetail(Integer homeworkId) {
        return homeworkMapper.getHomeworkDetail(homeworkId);
    }

    @Override
    public List<CourseHomeworkEntity> listClassAndCourse(Integer schoolCode, String uid) {
        return homeworkMapper.listClassAndCourse(schoolCode, uid);
    }

    @Override
    public List<JSONObject> listStudentByParentId(String uid) {
        return homeworkMapper.listStudentByParentId(uid);
    }

    @Override
    public List<HomeworkEntity> listStudentHomeworkInfo(Integer studentId) {
        return homeworkMapper.listStudentHomeworkInfo(studentId);
    }

    @Override
    public Integer countTeacherSendHomework(String uid, Integer classId, Integer courseId) {
        return homeworkMapper.countTeacherSendHomework(uid,classId,courseId);
    }

    @Override
    public Integer countStudentReceiveHomework(Integer studentId) {
        return homeworkMapper.countStudentReceiveHomework(studentId);
    }

    @Override
    public boolean insertHomeworkSendRecord(Integer homeworkId, String teacherId, List<String> sendParentOpenIdList) {
        return homeworkMapper.insertHomeworkSendRecord(homeworkId, teacherId, sendParentOpenIdList) > 0;
    }
}
